<?php

namespace App\Console\Commands;

use App\Models\Order;
use App\Models\OrderAudit;
use App\Models\OrderAuditLog;
use App\Models\OrderChild;
use App\Models\ProductCenter;
use App\Rep\OrderChildRep;
use App\Rep\SemiFinishProductRep;
use Illuminate\Console\Command;

class Test extends Command
{
    /**
     * The name and signature of the console command.
     * 控制台命令的名称和签名。
     * php artisan command:setorderchildprice
     * @var string
     */
    protected $signature = 'command:setorderchildprice';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '添加测试子订单数据';

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $order_list = Order::where('is_del',2)->get();
        foreach($order_list as $k=>$v){
            $this->info('===id='.$v->id.'开始===');
            $child_list = OrderChild::where('order_id',$v->id)->get();
            foreach($child_list as $kk=>$vv){
                $center = ProductCenter::where('product_id',$v->product_id)
                    ->where('model_number_id',$v->model_number_id)
                    ->where('specification_id',$v->specification_id)
                    ->where('job_type_id',$vv->job_type_id)
                    ->first();
                $vv->price = $center->price??0;
                $vv->save();
            }

        }
        return Command::SUCCESS;
    }

}
